<?php
function parse_backz( $id, $back_id, $back, $myamount, $key, $value, $tbl )
{
    global $g_disk_name;
    global $gametype;
    global $curruser;
    $err = "";
    $limit = $gametype == 0 ? "15" : "10";
    if ( $back != $myamount[$key]["back".$back_id] || $back == 100 )
    {
        if ( $back == 100 )
        {
            $back = 0;
        }
        else if ( $limit < $back )
        {
            if ( $back_id == 1 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【A盘】".$value."退水不能大於{$limit}！";
            }
            if ( $back_id == 2 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【B盘】".$value."退水不能大於{$limit}！";
            }
            if ( $back_id == 3 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【C盘】".$value."退水不能大於{$limit}！";
            }
            if ( $back_id == 4 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【D盘】".$value."退水不能大於{$limit}！";
            }
        }
        else if ( $back < 0 )
        {
            if ( $back_id == 1 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【A盘】".$value."退水不能小於0！";
            }
            if ( $back_id == 2 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【B盘】".$value."退水不能小於0！";
            }
            if ( $back_id == 3 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【C盘】".$value."退水不能小於0！";
            }
            if ( $back_id == 4 )
            {
                $err .= "<li style=\"color:#cc0000; font-weight:bold;\">【D盘】".$value."退水不能小於0！";
            }
        }
        if ( $err == "" )
        {
            if ( $gametype == 0 )
            {
                $ikey = $key;
                $subid = 0;
                if ( substr( strval( $key ), 0, 2 ) == "27" )
                {
                    $ikey = 27;
                    $subid = $key - 270;
                }
                else if ( substr( strval( $key ), 0, 2 ) == "36" )
                {
                    $ikey = 36;
                    $subid = $key - 360;
                }
                getdb( "update amounts{$tbl} set back".$back_id."={$back} ,updateid=".$curruser['id']." , updatedt = '".date( "Y-m-d H:i:s", systime( ) )."' where user_id={$id} and bettype={$ikey} and subid={$subid}" );
            }
            else if ( $gametype == 20 || $gametype == 21 || $gametype == 22 || $gametype == 23 )
            {
                getdb( "update amounts{$tbl} set back".$back_id."={$back} ,updateid=".$curruser['id']." , updatedt = '".date( "Y-m-d H:i:s", systime( ) )."' where user_id={$id} and bettype={$key} and subid=0" );
            }
            else
            {
                $bettypeArr = explode( "_", $key );
                getdb( "update amounts{$tbl} set back".$back_id."={$back} ,updateid=".$curruser['id']." , updatedt = '".date( "Y-m-d H:i:s", systime( ) )."' where user_id={$id} and bettype=".$bettypeArr[0]." and subid=".$bettypeArr[1] );
            }
        }
    }
    return $err;
}

if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$id = intval( $_GET['id'] );
if ( $id == 0 )
{
    exit( "You not input id!" );
}
$gametype = intval( getvar( "gametype" ) );
$chkGametype = chkGametype( $gametype );
switch ( $chkGametype )
{
    case 0 :
        $ui = new UI( true );
        $show3D3S = 0;
        $tbl = "";
        $tbl_change = $tbl;
        $change_betname = $g_betname;
        $i = 2;
        while ( $i < 6 )
        {
            $change_betname["27".$i] = "连肖".$i;
            $change_betname["36".$i] = "连尾".$i;
            ++$i;
        }
        unset( $change_betname[27] );
        unset( $change_betname[36] );
        unset( $change_betname[365] );
        $g_betname_3or5 = $change_betname;
        $listArr01 = array( 1, 2, 3, 5, 6, 28, 30, 15, 16, 35, 47 );
        break;
    case 1 :
    case 2 :
    case 3 :
	case 4 :
        include_once( "class_3d/CheckMode_3d.php" );
        $chk = new CheckMode_3d( $curruser['acl'], 1, $gametype );
        $chk->checkShow3dPage();
        $show3D3S = $chk->show3D3S;
        unset( $chk );
        $ui = new UI_3D( true );
        $ui->header();
        $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>".( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" );
        $ui->set( "jslink", $jslink );
        $tbl = $g_gametype_3d[$gametype]['en'];
        $tbl_change = "_{$tbl}";
        if ( 0 < $gametype && $gametype <= 15 )
        {
            $g_betname_3or5 = judge_type( $gametype );
            foreach ( $g_onlyN5Arr as $key => $value )
            {
                $listArr01[] = $value."_0";
            }
            foreach ( $g_2face_3d as $key => $value )
            {
                $listArr01[] = $value."_0";
            }
        }
        else if ( $gametype == 20 || $gametype == 21 || $gametype == 22 || $gametype == 23 )
        {
            $g_betname_3or5 = $g_betname_5h[$gametype];
            $listArr01 = $g_2face_5h[$gametype];
        }
		elseif($gametype==25 || $gametype==26)
		{
			foreach ($_sb_Arr as $key => $value)
            {
                $g_betname_3or5[$key."_0"] = $value;
            }

			$listArr01 = $g_2face_5h;
		}
        break;
    default :
        exit( "error gametype" );
}
$tpl = new Template2();
$conf = new Config();
if ( isset( $_SESSION['subaccount'] ) )
{
    $ui->showErrorPage( "你是子帐号，不能执行这个功能！" );
    exit();
}
$u = get_user( $id );
if ( !$u )
{
    diemsg( L_ERRMEMID );
}
$acl = $u['acl'];
$fixeddisk = intval( $conf->get( "fixed_disk" ) );
$titodoc = $g_gametype_3d[$gametype]['ch'];
if ( $curruser['acl'] < $acl )
{
    diemsg( "你没有权限存取！" );
}
$myamount = GetAmountSetting( $id, $gametype, 1 );
if ( $myamount == false )
{
    CreateAmount( $id, $gametype );
    $myamount = GetAmountSetting( $id, $gametype, 1 );
}
if ( ispost( ) )
{
    $errall = "";
    $errhidden = "";
    foreach ( $g_betname_3or5 as $key => $value )
    {
        $back1 = round( floatval( $_POST["back{$key}1"] ), 2 );
        $back2 = round( floatval( $_POST["back{$key}2"] ), 2 );
        $back3 = round( floatval( $_POST["back{$key}3"] ), 2 );
        $back4 = round( floatval( $_POST["back{$key}4"] ), 2 );
        $errall .= parse_backz( $id, 1, $back1, $myamount, $key, $value, $tbl_change );
        $errall .= parse_backz( $id, 2, $back2, $myamount, $key, $value, $tbl_change );
        $errall .= parse_backz( $id, 3, $back3, $myamount, $key, $value, $tbl_change );
        $errall .= parse_backz( $id, 4, $back4, $myamount, $key, $value, $tbl_change );
    }
    $tpl->set( "err", $errall );
    $myamount = GetAmountSetting( $id, $gametype, 1 );
}
$tbdList01 = "";
$tbdList02 = "";
$tbdList = "";
foreach ( $g_betname_3or5 as $key => $value )
{
    $updatedt = $myamount[$key]['updatedt'] == "0000-00-00 00:00:00" ? "" : date( "m-d H:i", strtotime( $myamount[$key]['updatedt'] ) );
    if ( $updatedt == "" )
    {
        $updateid = "";
    }
    else
    {
        $updateid = $myamount[$key]['account'] == G_SUPERACCOUNT ? "─&nbsp;操盘" : "─&nbsp;".$myamount[$key]['account'];
        $updateid .= $curruser['acl'] == 255 ? $myamount[$key]['updateid'] : "";
    }
    $tbdList = "<tr class=\"td2\">"."<th class=\"bgClc_{$gametype}\" align=\"right\">{$value}</th>"."<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack1\" name=\"back{$key}1\" value=\"".round( $myamount[$key]['back1'], 2 )."\"></td>"."<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack2\" name=\"back{$key}2\" value=\"".round( $myamount[$key]['back2'], 2 )."\"></td>"."<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack3\" name=\"back{$key}3\" value=\"".round( $myamount[$key]['back3'], 2 )."\"></td>"."<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack4\" name=\"back{$key}4\" value=\"".round( $myamount[$key]['back4'], 2 )."\"></td>"."<td class=\"bgClc_{$gametype}\">&nbsp;{$updatedt}&nbsp;{$updateid}</td>"."</tr>";
    if ( in_array( $key, $listArr01 ) )
    {
        $tbdList01 .= $tbdList;
    }
    else
    {
        $tbdList02 .= $tbdList;
    }
}
if ( !$g_init_mode_6h )
{
    unset( $g_gametype_3d[0] );
}
if ( !$g_init_mode_3d )
{
    $g_gametype_3d = array( 0 => $g_gametype_3d[0] );
}
$getOptionList = getOptionList( $gametype, "op.php?op=admin&fp=amount_3d&id={$id}" );
if ( ispost( ) )
{
    $funlist = "&nbsp;&nbsp;<a href=\"?op=admin&fp=subaccount&gametype={$gametype}&cmd=list\">回上一页</a>";
}
else
{
    $funlist = "&nbsp;&nbsp;<a href=\"javascript:history.back()\">回上一页</a>";
}
$tpl->load( "main", "amount_3d.htm" );
$tpl->set( array( "tbdList1" => $tbdList01, "tbdList2" => $tbdList02, "titodoc" => $titodoc, "myWidth" => "700", "url_reload" => "op.php?op=admin&fp=amount_3d&gametype={$gametype}&id={$id}", "action" => "?op=admin&fp=amount_3d&gametype={$gametype}&id={$id}", "submit" => L_OK, "account" => $u['account'], "name" => $u['name'], "id" => $id, "gametype" => "{$gametype}" ) );
echo title( "【".$g_gametype_3d[$gametype]['ch']."】总监退水管理", "【玩法切换】".$getOptionList.$funlist, "885" );
$tpl->show( "main" );
$ui->footer();
?>